from django.contrib import admin
from django.contrib.auth.models import AbstractUser
from django.db import models
from django.utils import timezone


class User(AbstractUser):
    """用户模型类"""
    mobile = models.CharField(max_length=11, unique=True, verbose_name='手机号')
    nickname = models.CharField(max_length=20, null=True, blank=True, verbose_name='昵称')
    sex = models.CharField(max_length=6, null=True, blank=True, verbose_name='性别')
    address = models.CharField(max_length=100, null=True, blank=True, verbose_name='地址')
    email_active = models.BooleanField(default=False, verbose_name='邮箱验证状态')
    update_time = models.DateTimeField(default = timezone.now, verbose_name="更新时间")
    class Meta:
        db_table = 'tb_users'
        verbose_name = '用户'
        verbose_name_plural = verbose_name


# admin站点的配置
# @admin.register(User)
# class UsersAdmin(admin.ModelAdmin):
#     """admin站点使用"""
#     list_display = ['id', 'username', 'mobile', 'email', 'last_login', 'is_superuser']
#     list_filter = ['is_superuser', 'email']
#     search_fields = ['username', 'email', 'mobile',]


class WriteArticle(models.Model):
    """用户文章模型类"""
    article_name = models.CharField(max_length=60,verbose_name='文章标题')
    article_classify = models.CharField(max_length=60,verbose_name='文章分类')
    article_text = models.CharField(max_length=15000,null=True, blank=True, verbose_name='文章内容')
    users_id = models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True, verbose_name="用户的文章id")
    update_time = models.DateTimeField(default = timezone.now, verbose_name="更新时间")

    class Meta:
        db_table = 'tb_article'
        verbose_name = '用户文章'
        verbose_name_plural = verbose_name